package Lee_code;

/**
 * @author blh
 * @date 2024年06月26日 13:23
 */
public class Lee_19_626 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode dummyHead = new ListNode(-1);
        dummyHead.next = head;
        // 实际上找的是第倒数第三个
        ListNode fast = dummyHead;
        for (int i=0; i<n-1; i++){
            fast = fast.next;
        }
        ListNode slow = dummyHead;
        while (fast!=null){
            slow= slow.next;
            fast = fast.next;
        }
        slow.next = slow.next.next;
        return dummyHead.next;
    }
}
